package com.guigu.www.denghao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.denghao.service.DHMenuService;
import com.guigu.www.mapper.MenuMapper;
import com.guigu.www.pojo.Menu;
import com.guigu.www.pojo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DHMenuServiceImpl implements DHMenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public PageVo<Menu> initMenu(Integer pageNum, Integer pageSize, String menuName) {
        IPage<Menu> iPage = new Page<>(pageNum,pageSize);
        QueryWrapper<Menu> wrapper = new QueryWrapper<>();
        wrapper.like("menu_name",menuName);
        iPage = menuMapper.selectPage(iPage,wrapper);
        return new PageVo<>(iPage.getTotal(),iPage.getRecords());
    }

    @Override
    public List<Menu> queryAllMenu() {
        return menuMapper.selectList(null);
    }

    @Override
    public Integer delMenu(Integer menuId, Integer menuState) {
        Menu menu = new Menu();
        menu.setMenuId(menuId);
        menu.setMenuState(menuState);
        return menuMapper.updateById(menu);
    }

}
